import csv

# 读
with open("/tmp/ip.csv", "r", encoding="utf-8") as f:
    reader = csv.reader(f)
    header = next(reader)
    print(header)
    for row in reader:
        print(row)

# 写
header = ["姓名", "年龄", "城市"]
data = [
    ["张三", 19, "广州"],
    ["李四", 23, "深圳"],
    ["王五", 32, "上海"],
]

with open("/tmp/person.csv", "w", encoding="utf-8") as f:
    writer = csv.writer(f)
    writer.writerow(header)
    writer.writerows(data)
    print("用户数据写入完成")
